<template>
<div>
  <el-radio-group class="flex">
    <el-radio v-for="item in options" :key="item.code">
  <span>{{ item.code }}：</span>
   <el-input class="radio-input" v-model="item.title"></el-input>
 <el-upload
  class="inlinebutton"
  action="https://jsonplaceholder.typicode.com/posts/"
  :show-file-list="false"
  :on-success="handleAvatarSuccess"
  :before-upload="beforeAvatarUpload"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar">
    <el-button v-else class="radio-button">点击上传</el-button>
      </el-upload>
    </el-radio>
    </el-radio-group>
    <el-button type="danger" @click="radioadd">+添加别的题</el-button>
</div>

</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      radio: 4,
      imageUrl: ''
    }
  },
  created () {
    console.log(this.options)
  },
  methods: {
    radioadd () {
      this.radio++
    },

    handleAvatarSuccess (res, file) {
      this.imageUrl = URL.createObjectURL(file.raw)
    },
    beforeAvatarUpload (file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    }
  }
}
</script>

<style lang="scss" scoped>
.flex {
  display: flex;
  flex-direction: column;
  .radio-input {
    width: 250px;
    margin-bottom: 20px;
    margin-right: 10px;
  }
  .inlinebutton {
    display: inline-block;
    .avatar {
      width: 70px;
      height: 70px;
      display: block;
    }
    .radio-button {
      height: 70px;
      border-radius: 10px;
    }
  }
}
</style>
